package com.atguigu.carousel.service.impl;

import com.atguigu.carousel.mapper.CarouselMapper;
import com.atguigu.carousel.service.CarouselService;
import com.atguigu.pojo.Carousel;
import com.atguigu.utils.R;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Name: MyComputer
 * @ClassName CarouselServiceImpl
 * @Description:
 * @date 2023/5/19 13:12
 */
@Service
public class CarouselServiceImpl implements CarouselService {

    @Autowired
    private CarouselMapper carouselMapper;
    /**
     * 查询轮播图数据，只要优先级最高的6条
     *  1.
     * @return
     */
    @Override
    public R list() {

        LambdaQueryWrapper<Carousel> carouselLambdaQueryWrapper = new LambdaQueryWrapper<>();
        carouselLambdaQueryWrapper.orderByDesc(Carousel::getPriority);

        List<Carousel> carousels = carouselMapper.selectList(carouselLambdaQueryWrapper);

        List<Carousel> collect = carousels.stream().limit(6).collect(Collectors.toList());

        return R.ok(collect);
    }
}
